﻿<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:properties="clr-namespace:BoilenEditor.Properties"
        x:Class="BoilenEditor.OpenWindow"
        ResizeMode="CanResizeWithGrip"
        properties:WindowSettings.SettingName="OpenWindowSettings"
        Title="Open Boilen File">
    <Window.CommandBindings>
        <CommandBinding Command="Open"
                        Executed="BrowseExecuted" />
        <CommandBinding Command="Close"
                        Executed="CloseExecuted" />
        <CommandBinding Command="Refresh"
                        Executed="RefreshExecuted" />
        <CommandBinding Command="Select"
                        CanExecute="SelectCanExecute"
                        Executed="SelectExecuted" />
        <CommandBinding Command="New"
                        CanExecute="CreateCanExecute"
                        Executed="CreateExecuted" />
        <CommandBinding Command="Properties"
                        Executed="PropertiesExecuted" />
    </Window.CommandBindings>
    <Window.InputBindings>
        <KeyBinding Command="Close"
                    Gesture="Ctrl+W" />
        <KeyBinding Command="Refresh"
                    Gesture="F5" />
        <KeyBinding Command="New"
                    Gesture="Ctrl+N" />
        <KeyBinding Command="Properties"
                    Gesture="Alt+P" />
    </Window.InputBindings>

    <DockPanel Margin="5">
        <Grid DockPanel.Dock="Top"
              Margin="5,0">
            <StackPanel HorizontalAlignment="Left"
                        Orientation="Horizontal">
                <TextBlock Text="Solution&#x000a;Directory"
                           TextAlignment="Right"
                           VerticalAlignment="Center" />
                <TextBox Margin="5"
                         Padding="4,0"
                         IsEnabled="False"
                         VerticalContentAlignment="Center"
                         Text="{Binding SolutionDirectory, Mode=OneWay}" />
                <Button Style="{StaticResource DialogButton}"
                        TabIndex="0"
                        Content="_Browse"
                        Command="Open" />
            </StackPanel>

            <StackPanel HorizontalAlignment="Right"
                        Orientation="Horizontal">
                <CheckBox x:Name="includeEmpty_"
                          Margin="0,0,10,0"
                          TabIndex="0"
                          VerticalAlignment="Center"
                          Content="_Include&#x000a;Empty"
                          IsChecked="{Binding IncludeEmptyProjects, Mode=OneTime}"
                          Checked="OnFilterChanged"
                          Unchecked="OnFilterChanged" />
                <TextBlock Text="Directory&#x000a;Filter"
                           TextAlignment="Right"
                           VerticalAlignment="Center" />
                <TextBox x:Name="filterBox_"
                         Margin="5"
                         MinWidth="50"
                         TabIndex="0"
                         VerticalContentAlignment="Center"
                         Text="{Binding ProjectDirectoryFilter, Mode=OneTime, Source={x:Static properties:Settings.Default}}"
                         TextChanged="OnFilterChanged" />
                <Button x:Name="refreshButton_"
                        Style="{StaticResource DialogButton}"
                        TabIndex="0"
                        Content="_Refresh"
                        Command="Refresh" />
            </StackPanel>
        </Grid>

        <StackPanel DockPanel.Dock="Bottom"
                    Orientation="Horizontal"
                    HorizontalAlignment="Right">
            <Button Style="{StaticResource DialogButton}"
                    TabIndex="5"
                    IsDefault="True"
                    Content="_Open"
                    Command="Select" />
            <Button Style="{StaticResource DialogButton}"
                    TabIndex="6"
                    IsCancel="True"
                    Content="_Cancel" />
        </StackPanel>

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="2*" />
            </Grid.RowDefinitions>

            <GroupBox Grid.Row="0"
                      Margin="5">
                <GroupBox.Header>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="Pro_jects" />
                        <TextBlock Text="{Binding Projects.Count, StringFormat=({0})}" VerticalAlignment="Center" />
                    </StackPanel>
                </GroupBox.Header>

                <ListBox Name="projectListBox_"
                         Style="{StaticResource FilesListBox}"
                         TabIndex="1"
                         SelectionMode="Extended"
                         ItemsSource="{Binding Projects, Mode=OneWay}"
                         SelectionChanged="ProjectSelectionChanged" />
            </GroupBox>

            <GridSplitter Grid.Row="1"
                          Height="3"
                          VerticalAlignment="Stretch"
                          HorizontalAlignment="Stretch"
                          IsTabStop="False"
                          Margin="5,0"
                          Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />

            <GroupBox Grid.Row="2"
                      Header="_Files"
                      Margin="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <Label Grid.Column="0"
                           Content="_Search:" />
                    <TextBox Name="searchBox_"
                             Grid.Column="1"
                             TabIndex="2"
                             VerticalContentAlignment="Center"
                             TextChanged="OnSearchTextChanged"
                             PreviewKeyDown="SearchBoxPreviewKeyDown" />
                    <Button Grid.Column="2"
                            Style="{StaticResource DialogButton}"
                            Margin="5,0,0,0"
                            TabIndex="3"
                            Content="Cr_eate"
                            Command="New" />

                    <ListBox Name="fileListBox_"
                             Grid.Row="1"
                             Grid.ColumnSpan="3"
                             Style="{StaticResource FilesListBox}"
                             TabIndex="4"
                             MouseDoubleClick="FileListBoxDoubleClick">
                        <ListBox.GroupStyle>
                            <StaticResource ResourceKey="FileGroupStyle" />
                        </ListBox.GroupStyle>
                    </ListBox>
                </Grid>
            </GroupBox>
        </Grid>
    </DockPanel>

    <FocusManager.FocusedElement>
        <Binding ElementName="searchBox_"
                 Mode="OneTime" />
    </FocusManager.FocusedElement>
</Window>
